﻿namespace WcfComposition
{
    using System;
    using System.Diagnostics.Contracts;
    using System.Linq;
    using System.ServiceModel;
    using System.ServiceModel.Activation;

    /// <summary>
    /// Responsible for providing Service Hosts which utilize MEF for runtime composition for RESTful services.
    /// </summary>
    public class ComposingWebServiceHostFactory : ServiceHostFactory
    {
        /// <summary>
        /// Creates a new instance of the ComposingWebServiceHost class for IIS.
        /// </summary>
        /// <param name="serviceType">A <see cref="Type"/> object.</param>
        /// <param name="baseAddresses">An array of <see cref="Uri"/> objects.</param>
        /// <returns>An <see cref="ServiceHost"/> based object capable of runtime composition.</returns>
        protected override ServiceHost CreateServiceHost( Type serviceType, Uri[] baseAddresses )
        {
            Contract.Ensures( serviceType != null );
            Contract.Ensures( baseAddresses.Count() > 0 );

            return new ComposingWebServiceHost( serviceType, baseAddresses );
        }
    }
}
